<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017\10\16 0016
 * Time: 17:27
 */
namespace Home\Controller;
use Home\Controller\CommonController;

class CustomerController extends CommonController{
    public function index(){
        if(empty($_SESSION['uid'])) {
            $this->redirect("/login/index");
            exit;
        }else{
            $customer = M("customer")->select();
            $customercou=M("customer")->count();
            $this->assign("customercou", $customercou);
            $this->assign("customer", $customer);
            $this->display();
        }
    }
    public function add(){
        if(IS_POST){
            $post=I("post.");
            $add = M("customer")->data($post)->add();
            if($add){
                echo true;
            }else{
                echo false;
            }
        }else{
            $this->display();
        }
    }
    //编号检测
    public function number_check(){
        $get=I("get.");
        $bol=M("customer")->where("number='{$get['number']}'")->select();
        if($bol){
            echo 1;
        }else{
            echo 0;
        }
    }
    public function edit(){
        if(IS_POST){
            $post=I("post.");
            $bol = M("customer")->where("id={$_GET['id']}")->data($post)->save();
            if($bol){
                echo true;
            }else{
                echo false;
            }
        }else{
            $customerinfo = M("customer")->where("id={$_GET['id']}")->select();
            $this->assign("customer", $customerinfo);
            $this->display();
        }
    }
    public function del(){
        $del=M("customer")->where("id={$_GET['id']}")->delete();
        if($del){
            echo 1;
        }else{
            echo 0;
        }
    }
    //空方法
    public function _empty(){
        $this->display("没有这个方法");
    }
}